package com.fjl.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class TestService {
	public TestService() {
		System.out.println("TestService================");
	}

	@Primary
	public void hello() {
		System.out.println("hello,world ~~~");
	}

	@Autowired
	private JdbcTemplate jdbcTemplate;


	@Transactional
	public void test() {
		System.out.println("=== 开始插入 ===");
		jdbcTemplate.update("INSERT INTO t0(name) VALUES (?)", "Tom");

//		int x = 1 / 0;  // 故意抛出异常触发回滚

		jdbcTemplate.update("INSERT INTO t0(name) VALUES (?)", "Jerry");
	}
}
